package com.ruoyi.system.wnjk.config;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

@Component
public class OrderStatusScheduler {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Scheduled(fixedRate = 20000) // 每5分钟执行一次
    public void cancelUnpaidOrders() {
//        System.out.println("开始~~~");
        String sql = "UPDATE wnjk_consultation_order SET order_status = '已取消' " +
                "WHERE order_status = '待支付' " +
                "AND consultation_time <= NOW() - INTERVAL 30 MINUTE " +
                "AND is_deleted = 1";
        jdbcTemplate.update(sql);
//        System.out.println("结束~~~");
    }
}
